/*
 * @Description:
 * @Author: Rfan
 * @Date: 2021-10-29 22:59:41
 * @LastEditTime: 2022-05-27 14:30:09
 */

import { observable, action } from 'mobx';
import { selectItemByKey } from '@/utils/list';

// 观察者
const wsState = observable({
  msgType: [
    { code: 0, key: 'normal', name: '普通消息' },
    { code: 1, key: 'archiveImport', name: '档案接收进度消息' },
    { code: 2, key: 'archiveExport', name: '档案导出进度消息' },
    { code: 3, key: 'formatConvert', name: '格式转换进度消息' },
    { code: 4, key: 'archiveDetection', name: '档案检测进度消息' }
  ],
  normal: null,
  archiveImport: null,
  archiveExport: null,
  formatConvert: null,
  archiveDetection: null
});

// 方法
const wsActions = {
  /**
   * @description: 设置动态路由表
   */
  setLatestMsg: action((type: number, msg: any) => {
    const typeKey: string = selectItemByKey(type, wsState.msgType, 'code')?.key;
    if (typeKey) {
      // @ts-ignore
      wsState[typeKey] = msg;
    }
  })
};

export { wsState, wsActions };
